﻿
namespace YY.Admin.Application.Service
{
    public class SysUserService : ISysUserService
    {
        // 模拟数据，实际使用时连接数据库
        private readonly List<SysUser> _users = new()
        {
          
        };

        public async Task<List<SysUser>> GetUsersAsync()
        {
            await Task.Delay(200);
            return _users.ToList();
        }

        public async Task<SysUser?> GetUserByIdAsync(int id)
        {
            await Task.Delay(100);
            return _users.FirstOrDefault(u => u.Id == id);
        }

        public async Task<bool> CreateUserAsync(SysUser user)
        {
            await Task.Delay(300);
            user.Id = _users.Max(u => u.Id) + 1;
            _users.Add(user);
            return true;
        }

        public async Task<bool> UpdateUserAsync(SysUser user)
        {
            await Task.Delay(200);
            var existingUser = _users.FirstOrDefault(u => u.Id == user.Id);
            if (existingUser != null)
            {
                return true;
            }
            return false;
        }

        public async Task<bool> DeleteUserAsync(int id)
        {
            await Task.Delay(150);
            var user = _users.FirstOrDefault(u => u.Id == id);
            if (user != null)
            {
                _users.Remove(user);
                return true;
            }
            return false;
        }
    }
}
